package com.gitee.wsgalaxy.gnodroid;

import android.app.Service;
import android.content.Context;
import android.util.Log;

import com.gitee.wsgalaxy.gnodroid.module.GndDeviceInfoModule;
import com.gitee.wsgalaxy.gnodroid.module.GndIdleModule;
import com.gitee.wsgalaxy.gnodroid.module.GndModule;
import com.gitee.wsgalaxy.gnodroid.module.GndScreencapModule;

import java.util.ArrayList;

/**
 * Created by wsgalaxy on 3/17/18.
 */

//存储全局变量
public final class GndGlobal {
    public static int BYTE_BUFFER_SIZE = 1024 * 10;
    public static byte[] MESSAGE_TAG = {'o', 'x', 'o', 'x', 'o', 'x', 'o', 'x'};
    public static int PORT = 4396;
    static ArrayList<GndModule> modules_list  = null;       //存储模块列表
    public  static Context context = null;

    public final static int GND_JSON_STATUS_NULL = 0x0000;
    public final static int GND_JSON_STATUS_SUCCEED = 0x0001;
    public final static int GND_JSON_STATUS_FAILURE = 0x0002;

    public final static String GND_MESSAGE_PERMISSION_DENY = "permission deny";

    //注册模块
    static boolean registeModule(GndModule module)
    {
        Log.d("gnd", "registe module : " + module.getModuleId());
        return modules_list.add(module);
    }

    //程序启动时注册所有模块
    public static void registeAllModule()
    {
        if (modules_list != null) {
            return;
        }

        modules_list = new ArrayList<GndModule>();
        registeModule(new GndIdleModule());
        registeModule(new GndDeviceInfoModule());
        registeModule(new GndScreencapModule());
    }

    //使用id匹配模块
    public static GndModule matchModule(String mid)
    {
        for (GndModule m : modules_list) {
            if (m.checkModuleId(mid)) {
                return m;
            }
        }

        return null;
    }

    public static void setContext(Context ctx)
    {
        context = ctx;
    }


}
